import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t=in.nextInt();
        int cnt=0;
        while(cnt<t){
            int l=in.nextInt();
            int r=in.nextInt();
            String s1=String.valueOf(l);
            String s2=String.valueOf(r);
            int n1=s1.length();
            int n2=s2.length();
            int res=1;
            int res2=1;
            for(int a=2;a<=n1;a++){
                res=res*10+a;
            }
            for(int a=2;a<=n2;a++){
                res2=res2*10+a;
            }
            if(res>=l&&res<=r||res2>=l&&res2<=r){
                if(res>=l&&res<=r){
                    System.out.println(res);
                }else{
                    System.out.println(res2);
                }
            }else{
                System.out.println(-1);
            }
            cnt++;
        }
    }
}